package com.etc.zmall.dao.impl;

import java.util.List;

import com.etc.util.DBUtil;
import com.etc.util.PageData;
import com.etc.zmall.dao.OrdersDao;
import com.etc.zmall.entity.Orders;

/**
 * OrdersDaoImpl
 * @author knowno
 *
 */
public class OrdersDaoImpl implements OrdersDao{
	
	/**
	 * 新增订单 
	 */
	@Override
	public boolean addOrders(Orders orders) {
		String sql = "insert into tbl_order values(null,?,?,?,?,?)";
		return DBUtil.exUpdate(sql,orders.getOrdersum(),orders.getOrderdate(),orders.getOrderstate()
				,orders.getUserid(),orders.getTotal());
	}
	/**
	 * 删除订单
	 */
	@Override
	public boolean delOrders(int orderid) {
		String sql = "delete from tbl_order where orderid=?";
		return DBUtil.exUpdate(sql, orderid);
	}
	/**
	 * 修改订单信息
	 */
	@Override
	public boolean upOrders(int ordersum, int orderstate, double total, int orderid) {
		String sql = "update tbl_order set ordersum=?,orderstate=?,total=? where orderid=?";
		return DBUtil.exUpdate(sql,ordersum,orderstate,total,orderid);
	}
	/**
	 * 修改订单状态
	 */
	@Override
	public boolean upOrdersState(int orderstate, int orderid) {
		String sql = "update tbl_order set orderstate =? where orderid=?";
		return DBUtil.exUpdate(sql, orderstate, orderid);
	}
	/**
	 * 用户查看订单
	 */
	@Override
	public PageData<Orders> queryOrdersUserid(int page, int pageSize, int userid) {
		String sql = "select * from tbl_order where userid=?";
		return DBUtil.exQueryByPage(sql, Orders.class, page, pageSize, userid);
	}
	/**
	 * 根据订单状态查询
	 */
	
	@Override
	public PageData<Orders> queryOrdersState(int page, int pageSize, int orderstate) {
		String sql = "select * from tbl_order where orderstate=?";
		return DBUtil.exQueryByPage(sql, Orders.class, page, pageSize, orderstate);
	}
	/**
	 * 查看订单详情
	 */
	@Override
	public Orders queryOneOrders(int orderid) {
		String sql = "select * from tbl_order where orderid = ?";
		List<Orders> list = (List<Orders>) DBUtil.exQuery(sql, Orders.class, orderid);
		if (list.size() == 0) {
			return null;
		}
		return list.get(0);
	}

}
